package com.sts.controller;

import com.sts.common.result.Result;
import com.sts.dto.TicketCommentCreateDTO;
import com.sts.dto.TicketCommentDTO;
import com.sts.service.TicketCommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor
public class CommentController {

    private final TicketCommentService commentService;

    /** 新增评论 */
    @PostMapping
    public Result<Long> add(@RequestBody TicketCommentDTO dto,
                            @RequestHeader("X-User-Id") Long authorId) {
        return Result.success(commentService.addComment(dto, authorId));
    }

    /** 根据工单查评论 */
    @GetMapping("/ticket/{ticketId}")
    public Result<List<TicketCommentDTO>> list(@PathVariable Long ticketId) {
        return Result.success(commentService.listByTicket(ticketId));
    }

    /** 删除评论 */
    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Long id,
                               @RequestHeader("X-User-Id") Long operatorId) {
        commentService.deleteComment(id, operatorId);
        return Result.success();
    }
}